package netty.buf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;

import java.nio.charset.Charset;

/**
 * @author 帅小伙
 * @date 2022/1/17
 * @description
 */
public class NettyBuf01 {


    public static void main(String[] args) {

        //
        ByteBuf byteBuf1 = Unpooled.buffer(10);
        ByteBuf byteBuf = Unpooled.copiedBuffer("hello world", Charset.forName("utf-8"));

        // 使用相关的方法
        if(byteBuf.hasArray()){
            byte[] content = byteBuf.array();

            //讲content转成字符串
            System.out.println(new String(content, Charset.forName("utf-8")));

            System.out.println("byteBuf:"+byteBuf);


            byteBuf.readableBytes();// 可读字节数
        }

    }
}
